<script setup>
import Login from './view/user/Login.vue';
import Register from './view/user/Register.vue';
import AISearch from './components/AISearch.vue';
import ChatDialog from './components/ChatDialog.vue';
import { useShowLoginDialogStore } from '@/store/showLoginDiaolg';
import { useShowRegisterDialogStore } from '@/store/showRegisterDiaolg';
import { useShowAISearchStore } from '@/store/showAISearch';
import { useShowChatDialogStore } from './store/showChatDialog';

// 显示用户登录弹框
const showLoginDialogStore = useShowLoginDialogStore()
// 显示用户注册弹框
const showRegisterDialogStore = useShowRegisterDialogStore()
// 显示AI搜索框
const showAISearchStore = useShowAISearchStore();
const showChatDialogStore = useShowChatDialogStore()

// 显示/隐藏AI搜索框
const showAIPanel = () => {
  showAISearchStore.setShowAISearch(!showAISearchStore.getShowAISearch())
}

// 显示/隐藏聊天搜索框
const showChatDialog = () => {
  showChatDialogStore.setShowChatDialog(!showChatDialogStore.getShowChatDialog())
}

// 返回顶部
// 获取按钮元素
// const backToTopBtn = document.querySelector("#to-top-btn");
// 监听滚动事件，控制按钮显示/隐藏
// window.addEventListener("scroll", function () {
//   if (window.pageYOffset > 300) {
//     backToTopBtn.style.display = "block";
//   } else {
//     backToTopBtn.style.display = "none";
//   }
// });
const toTop = () => {
  window.scrollTo({
    top: 0,
    behavior: "smooth"
  });
}
</script>

<template>
  <router-view></router-view>

  <!-- 登录组件（显示时才创建弹窗，防止重复请求图片验证码） -->
  <Login v-if="showLoginDialogStore.showLoginDialog"></Login>
  <!-- 注册组件（显示时才创建弹窗，防止重复请求图片验证码） -->
  <Register v-if="showRegisterDialogStore.showRegisterDialog"></Register>

  <!-- AI问答 -->
  <div class="global-component-box">
    <div class="btn-panel">
      <div id="to-top-btn" class="to-top-btn" @click="toTop">
        <span class="iconfont icon-fanhuidingbu"></span>
      </div>
      <div class="ai-search-btn" @click="showAIPanel">
        <span class="iconfont icon-ai ai-icon"></span>
      </div>
      <div class="chat-btn" @click="showChatDialog">
        <span class="iconfont icon-AI-02 ai-icon"></span>
      </div>

      <div class="ai-search-box" v-show="showAISearchStore.showAISearch">
        <AISearch></AISearch>
      </div>
      <div class="chat-dialog" v-if="showChatDialogStore.showChatDialog">
        <ChatDialog></ChatDialog>
      </div>
    </div>
  </div>
</template>

<style scoped>
.global-component-box {
  position: fixed;
  right: 20px;
  bottom: 20px;
}

.global-component-box .btn-panel {
  position: relative;
  /* display: flex; */
  align-items: end;
}

.global-component-box .btn-panel .ai-search-btn,
.global-component-box .btn-panel .to-top-btn,
.global-component-box .btn-panel .chat-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  background-color: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(50, 50, 50, .04);
  cursor: pointer;
}

.global-component-box .btn-panel .to-top-btn .iconfont {
  font-size: 20px;
}

.global-component-box .btn-panel .ai-search-btn .ai-icon {
  position: relative;
}

.global-component-box .btn-panel .ai-search-box,
.global-component-box .btn-panel .chat-dialog {
  width: 700px;
  height: 600px;
  position: absolute;
  right: 60px;
  bottom: 0;
  z-index: 2;
  cursor: default;
}

.global-component-box .btn-panel .chat-btn .btn-name {
  font-size: 16px;
}
</style>